package initialize

import (
	v1 "gitee.com/baal1990/epidemic/api/v1"
	"gitee.com/baal1990/epidemic/global"
	"gitee.com/baal1990/epidemic/middleware"
	"gitee.com/baal1990/epidemic/router/manageend"
	"gitee.com/baal1990/epidemic/router/system"
	"gitee.com/baal1990/epidemic/router/userend"
	"github.com/gin-gonic/gin"
)

// 初始化总路由

func Routers() *gin.Engine {
	Router := gin.Default()
	Router.Use(middleware.CorsByRules())
	Router.Use(middleware.XWsse()) //校验X-WSSE
	Router.Use(middleware.ReqTimeLog())
	var dfitc = system.Dfitc{}
	rulControl := Router.Group("").Use(middleware.UriControl(global.GVA_CONFIG.System.UriLimiterExpire, global.GVA_CONFIG.System.UriControlLimitCount))
	{
		rulControl.POST("/epidemic/msg-code", dfitc.MsgCode) // 发送验证码
	}
	Router.POST("/login", dfitc.Login)         // 登录
	Router.GET("/refresh", dfitc.RefreshToken) // 刷新token
	DfitcGroup := Router.Group("")
	DfitcGroup.Use(middleware.Auth())
	{
		DfitcGroup.GET("/epidemic/user/dict", v1.ApiGroupApp.EpidemicApiGroup.EpidemicUserApi.Dict) // 数据字典
		manageend.ManageRouter(Router)
		userend.UserRouter(Router)
	}
	global.GVA_LOG.Info("router register success")
	return Router
}
